package com.qf.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.common.http.Result;
import com.qf.entiy.dto.Goods;
import com.qf.service.impl.GoodsService;
import com.qf.service.impl.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Controller
@RequestMapping("goods")
public class GoodsController {

    @Autowired
    private GoodsTypeService goodsTypeService;
    @Autowired
    private GoodsService goodsService;

    //跳转到平台管理审核的商品列表页,所有上传的商品都可见
    @RequestMapping("list")
    public String toList(Model model,
                         @RequestParam(value = "goodsTypeId", required = false, defaultValue = "0") Long goodsTypeId) {

        //根据左侧菜单栏的选项,展示不同类型的商品
        //分页

        model.addAttribute("goodsTypes", goodsTypeService.list());
        model.addAttribute("goodsList", goodsService.getByTypeId(goodsTypeId));
        return "goods/list";
    }

    //商品上架操作
    @RequestMapping("up")
    @ResponseBody       //ajax操作,需要注解
    public Result<?> up(@RequestParam(value = "id", required = true) Long goodsId) {
        goodsService.up(goodsId);//修改商品的状态state.(0:待审核[默认];;1:上架;;2下架)
        return Result.success();
    }

    //商品下架
    @RequestMapping("down")
    @ResponseBody
    public Result<?> down(@RequestParam(value = "id", required = true) Long goodsId) {
        goodsService.down(goodsId); //修改商品的状态state.(0:待审核[默认];;1:上架;;2下架)
        return Result.success();
    }

    //删除商品
    @RequestMapping("del")
    @ResponseBody
    public Result<?> del(@RequestParam(value = "id", required = true) Long goodsId) {
        goodsService.removeById(goodsId);
        return Result.success();
    }


}
